package com.view;

/**************************************************** IMPORT ****************************************************/
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import com.diana.*;


public class DianaScreen extends Screen implements OnKeyListener{


	/************ DECLARATIONS ***************/
	private LinearLayout menuLayout;
	private ImageButton menuButton;
	private EditText editText;
	private String brutString;


	/************ CONSTRUCTOR ****************/
	public DianaScreen(MainActivity activity) {
		super(activity,R.layout.diana_interface);
	} 


	/************** METHODES *****************/
	/**
	 * @brief Instantiation of widgets and listeners.
	 */
	public void recuperationWidgetInterface(){
		setMenuLayout( (LinearLayout) getActivity().findViewById(R.id.menu_layout));
		setMenuButton((ImageButton)  getActivity().findViewById(R.id.menuButton));

		setEditText((EditText) getActivity().findViewById(R.id.editText_Test));
		editText.setOnKeyListener(this);
	}

	/**
	 * @brief Show the view.
	 */
	@Override
	public void display() {
		recuperationWidgetInterface();
	}

	/**
	 * @brief Close the view.
	 */
	@Override
	public void close() {
		// TODO Auto-generated method stub

	}

	/**
	 * @brief Display the menu.
	 */
	public void showMenu(){
		if ( this.getMenuLayout().getVisibility() == View.GONE){
			this.getMenuLayout().setVisibility(View.VISIBLE);
		}
		else{
			this.getMenuLayout().setVisibility(View.GONE);
		}
	}

	/**
	 * @brief Detect the send request of a sentence.
	 * @param v : current view.
	 * @param keyCode : enter button.
	 * @param event : up of the button.
	 */
	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {

		if ( event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_ENTER){
			this.getActivity().getRecorder().newStringDetected(editText.getText().toString());
		}

		return false;
	}

	
	/************* ACCESSORS *************/
	public ImageButton getMenuButton() {
		return menuButton;
	}

	public void setMenuButton(ImageButton menuButton) {
		this.menuButton = menuButton;
	}

	public LinearLayout getMenuLayout() {
		return menuLayout;
	}

	public void setMenuLayout(LinearLayout menuLayout) {
		this.menuLayout = menuLayout;
	}


	public EditText getEditText() {
		return editText;
	}


	public void setEditText(EditText editText) {
		this.editText = editText;
	}


	public String getBrutString() {
		return brutString;
	}


	public void setBrutString(String brutString) {
		this.brutString = brutString;
	}
}
